<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------

namespace Lg\Http;

use Lg\File\UploadedFile;

/**
 * Description of Input
 *
 * @author Allen <allen@lg4.cn>
 */
class Input {

    public static function all() {
        return Request::classic()->query->all() + Request::classic()->request->all();
    }

    /**
     * Get an item from the input data.
     * (GET, POST, PUT, and DELETE)
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    public static function get($key, $default = null) {
        return Request::classic()->get($key, $default);
    }

    /**
     * Get an item from $_GET.
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    public static function query($key = null, $default = null) {
        if (is_null($key) && is_null($default)) {
            return Request::classic()->query->all();
        }
        return Request::classic()->query->get($key, $default);
    }

    /**
     * Get an item from $_POST.     * 
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    public static function post($key = null, $default = null) {
        if (is_null($key) && is_null($default)) {
            return Request::classic()->request->all();
        }
        return Request::classic()->request->get($key, $default);
    }
    
    /**
     * 
     * @param string $key
     * @return \Symfony\Component\HttpFoundation\File\UploadedFile
     */
    public static function file($key = null) {   
        return UploadedFile::createFromBase(Request::classic()->files->get($key));        
    }

    public static function cookie($key = null, $default = null) {
        if (is_null($key) && is_null($default)) {
            return Request::classic()->cookies->all();
        }
        return Request::classic()->cookie($key, $default);
    }

    /**
     * 
     * @return string PATH_INFO
     */
    public static function pathinfo() {
        return Request::classic()->getPathInfo();
    }

    /**
     * 
     * @return string Base Url
     */
    public static function baseUrl() {
        return Request::classic()->getBaseUrl();
    }

    public static function basePath() {
        return Request::classic()->getBasePath();
    }

    /**
     * method (get|post)
     * @return string 
     */
    public static function method() {
        return Request::classic()->getMethod();
    }

    public static function isMethod($method) {
        return Request::classic()->isMethod($method);
    }

    /**
     * 
     * @return \Lg\Http\Request
     */
    public static function req() {
        return Request::classic();
    }

    public static function getLocale() {
        return Request::classic()->getLocale();
    }

    public static function languages() {
        return Request::classic()->getLanguages();
    }

}
